﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VmGui.localhost;
using System.Web.Services.Protocols;

namespace VmGui
{
    public partial class FormCrudRepresentada : Form
    {
        List<Representada> listaRepresentada;

        public FormCrudRepresentada()
        {
            InitializeComponent();
        }

        private void bNovoRepresentante_Click(object sender, EventArgs e)
        {
            FormNovoRepresentada fnr = new FormNovoRepresentada();
            fnr.ShowDialog();
            listar_Representada();
        }

        public void listar_Representada()
        {
            this.Cursor = Cursors.WaitCursor;
            Service1 sv = new Service1();

            try
            {
                listaRepresentada = sv.listar_repre().ToList();
                dataGridView1.DataSource = listaRepresentada;
            }
            catch (SoapException erro)
            {
                MessageBox.Show(erro.Message);
            }
            this.Cursor = Cursors.Default;
        }

        private void FormCrudRepresentada_Load(object sender, EventArgs e)
        {
            listar_Representada();
        }

        private void bExcluirRepresentante_Click(object sender, EventArgs e)
        {
            Service1 sv = new Service1();
            Representada repre = new Representada();
            try
            {
                string x = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                repre.CodRepre = Convert.ToInt32(x);

                if (MessageBox.Show("Tem certeza que deseja excluir ?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    sv.excluir_repre(repre);
                    MessageBox.Show("Registro Excluído com sucesso!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    listar_Representada();
                }
            }
            catch (SoapException erro)
            {
                MessageBox.Show(erro.Message);
            }
        }
    }
}